香橙派orangepi pc plus h3 启动tf卡制作

您所在的位置:网站首页 香橙派4 openwrt 香橙派orangepi pc plus h3 启动tf卡制作

香橙派orangepi pc plus h3 启动tf卡制作

#香橙派orangepi pc plus h3 启动tf卡制作| 来源: 网络整理| 查看: 265

前言 环境介绍: 1.编译环境

Ubuntu 18.04.5 LTS

2.SDK

orangepi Linux 5.4 SDK

3.uboot

v2020.04

参考说明:

Bootable SD card

一、h3 tf卡分区 1.1说明

tf卡的起始地址处放的是分区表MBR(占用512B)或者GPT,为了保证tf卡还能用于其他目的,所以前8KB是不能用的; 8KB开始存放uboot-spl以及uboot镜像; 后续未使用区域可以分成FAT分区 + 其他分区,FAT分区中存放linux kernel + DTB文件 + boot.scr,其他分区主要存放根文件系统,或者其他分区; 这些都是全志内部固化的流程,芯片上电后首先运行内部一段引导程序uboot-spl,然后按照一定的优先级去遍历emmc tf nand usb等看是否能引导程序,如果是tf/emmc,则会在8KB的偏移处引导程序(uboot-spl),再引导uboot,uboot会从sd卡FAT分区内引导linux内核,解析boot.scr,获取bootcmd,再从其他分区加载根文件系统。

1.2分区

tf分区有多种方式,命令+可视化软件 命令fdisk工具

[email protected]:/# ls /dev/sd* /dev/sda /dev/sda1 /dev/sdb /dev/sdb1 [email protected]:/# fdisk /dev/sdb #sdb为我的tf卡 欢迎使用 fdisk (util-linux 2.31.1)。 更改将停留在内存中,直到您决定将更改写入磁盘。 使用写入命令前请三思。 命令(输入 m 获取帮助): p #查看分区 Disk /dev/sdb:29.7 GiB,31914983424 字节,62333952 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0xc32483ee 设备 启动 起点 末尾 扇区 大小 Id 类型 /dev/sdb1 8192 4571135 4562944 2.2G 83 Linux #原来的分区 命令(输入 m 获取帮助): d 1 #删除分区1 已选择分区 1 分区 1 已删除。 命令(输入 m 获取帮助): n #新分区 分区类型 p 主分区 (0个主分区,0个扩展分区,4空闲) e 扩展分区 (逻辑分区容器) 选择 (默认 p): p 分区号 (1-4, 默认 1): 1 第一个扇区 (2048-62333951, 默认 2048): 2048 #分区1默认从2048开始,这样我们的uboot不会被删除 上个扇区,+sectors 或 +size{K,M,G,T,P} (2048-62333951, 默认 62333951): +50M #分区1大小50M 创建了一个新分区 1,类型为“Linux”,大小为 50 MiB。 命令(输入 m 获取帮助): t #分区1格式化 已选择分区 1 Hex 代码(输入 L 列出所有代码): 6 #6 格式化为FAT16,可输入L查看其他格式 已将分区“Linux”的类型更改为“FAT16”。 命令(输入 m 获取帮助): p #检查是否新分区 Disk /dev/sdb:29.7 GiB,31914983424 字节,62333952 个扇区 单元:扇区 / 1 * 512 = 512 字节 扇区大小(逻辑/物理):512 字节 / 512 字节 I/O 大小(最小/最佳):512 字节 / 512 字节 磁盘标签类型:dos 磁盘标识符:0x545cf8bb 设备 启动 起点 末尾 扇区 大小 Id 类型 /dev/sdb1 2048 104447 102400 50M 6 FAT16 #成功将分区1格式化为FAT16 命令(输入 m 获取帮助): w #将分区写入卡 分区表已调整。 将调用 ioctl() 来重新读分区表。 正在同步磁盘。

正常上面的分区格式都完成就可以使用了,但不知道为啥我的分区格式是不能能用,当时在这里也坑好久! 后来是采用gparted图形分区工具才解决。 软件通过sudo apt install gparted安装。 gparted图形分区工具 打开软件看到我的分区是有问题的,用这个工具格式化之后可以正常使用。 软件使用较简单,不细说了。 分区1一定要格式化为FAT16/32,要不然uboot环境变量有问题,我这里选择FAT32 。坑在这里。

一、uboot烧录

tf卡插入Ubuntu

cd orangepi/orangepi-build/u-boot/v2020.04/ ls u-boot-sunxi-with-spl.bin u-boot-sunxi-with-spl.bin dd if=u-boot-sunxi-with-spl.bin of=/dev/sdX bs=1024 seek=8 X为TF卡分配的字母 我这里是/dev/sdb 解释:以1024B,也就是1K为块单位大小,跳过8块。 也就是从TF卡的8KB处开始写入文件u-boot-sunxi-with-spl.bin。 二、内核

tf卡的分区1 mount到/mnt 将编译生成的orange-pi-5.4/arch/arm/boot/zImage、orange-pi-5.4/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dtb拷贝到分区1

mount /dev/sdb1 /mnt/ #dev/sdb1 mount到/mnt cp orangepi/orangepi-build/kernel/orange-pi-5.4/arch/arm/boot/zImage /mnt #拷贝zImage cp orangepi/orangepi-build/kernel/orange-pi-5.4/arch/arm/boot/dts/sun8i-h3-orangepi-pc-plus.dtb /mnt #拷贝dtb sync #同步 umount /mnt #umount sudo eject /dev/sdb1 #移除tf卡 三、测试uboot、内核

完成上述操作之后将卡插入板卡,上电。 打印如下:

U-Boot SPL 2020.04-orangepi (Jan 24 2021 - 22:53:19 +0800) DRAM: 1024 MiB Trying to boot from MMC1 #以上为spl打印 #如下才是uboot打印 U-Boot 2020.04-orangepi (Jan 24 2021 - 22:53:19 +0800) Allwinner Technology CPU: Allwinner H3 (SUN8I 1680) Model: Xunlong Orange Pi PC Plus DRAM: 1 GiB MMC: Device '[email protected]': seq 1 is in use by '[email protected]' [email protected]: 0, [email protected]: 2, [email protected]: 1 Loading Environment from FAT... OK #能正常识别分区,加载环境变量 In: serial Out: serial Err: serial Net: phy interface0 eth0: [email protected] starting USB... Bus [email protected]: USB EHCI 1.00 Bus [email protected]: USB OHCI 1.0 Bus [email protected]: USB EHCI 1.00 Bus [email protected]: USB OHCI 1.0 Bus [email protected]: USB EHCI 1.00 Bus [email protected]: USB OHCI 1.0 Bus [email protected]: USB EHCI 1.00 Bus [email protected]: USB OHCI 1.0 scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning bus [email protected]1c1d000 for devices... 1 USB Device(s) found scanning bus [email protected] for devices... 1 USB Device(s) found scanning usb for storage devices... 0 Storage Device(s) found Autoboot in 5 seconds, press to stop #按空格进入uboot命令 => saveenv Saving Environment to FAT... OK #能正常保存环境变量 => load mmc 0:1 0x43000000 sun8i-h3-orangepi-pc-plus.dtb # mmc0(tf卡)分区1加载dtb 31609 bytes read in 5 ms (6 MiB/s) => load mmc 0:1 0x42000000 zImage # mmc0(tf卡)分区1加载zImage 7183328 bytes read in 351 ms (19.5 MiB/s) => bootz 0x42000000 - 0x43000000 #bootz 命令启动内核 ## Flattened Device Tree blob at 43000000 Booting using the fdt blob at 0x43000000 EHCI failed to shut down host controller. Loading Device Tree to 49ff5000, end 49fffb78 ... OK Starting kernel ... Uncompressing Linux... done, booting the kernel.

这里说一下: Image是Linux内核镜像文件; zImage 是经过 gzip 压缩后的Image; uImage 是老版本 uboot 专用的镜像文件,uImag 是在 zImage 前面加了一个长度为 64字节的“头”,这个头信息描述了该镜像文件的类型、加载位置、生成时间、大小等信息。但是新的uboot已经支持了zImage启动!很少使用uImage了。 zImage可通过下面方法生成uImage

mkimage -A arm -O linux -T kernel -C none -a 0x46000000 -e 0x46000000 -n linux-5.4.65 -d zImage uImage 0x46000000,内核在主存运行的起始位置,这里是0x46000000,根据数据手册。 全志的主存起始地址好像在0x40000000。 偏移了0x6000000是因为U-boot文件,设备树文件,内核文件都在主存里,随便偏移了0x6000000,保证不会覆盖掉这些文件即可。 linux-5.4.65 Linux内核版本

uboot下面通过下面方式加载、启动

=> load mmc 0:1 0x43000000 sun8i-h3-orangepi-pc-plus.dtb 31609 bytes read in 4 ms (7.5 MiB/s) => load mmc 0:1 0x42000000 uImage 7183392 bytes read in 351 ms (19.5 MiB/s) => bootm 0x42000000 - 0x43000000 #启动命令更改为bootm ## Booting kernel from Legacy Image at 42000000 ... Image Name: linux-5.4.65 Image Type: ARM Linux Kernel Image (uncompressed) Data Size: 7183328 Bytes = 6.9 MiB Load Address: 46000000 Entry Point: 46000000 Verifying Checksum ... OK ## Flattened Device Tree blob at 43000000 Booting using the fdt blob at 0x43000000 EHCI failed to shut down host controller. Loading Kernel Image Loading Device Tree to 49ff5000, end 49fffb78 ... OK Starting kernel ... 四、uboot启动命令配置

以上都是通过手动输入命令启动内核,下面修改环境变量自动启动内核 通过设置bootcmd环境变量即可!

=> setenv bootcmd 'load mmc 0:1 0x43000000 sun8i-h3-orangepi-pc-plus.dtb; load mmc 0:1 0x42000000 zImage; bootz 0x42000000 - 0x43000000' => saveenv Saving Environment to FAT... OK => boot 31609 bytes read in 4 ms (7.5 MiB/s) 7183328 bytes read in 351 ms (19.5 MiB/s) ## Flattened Device Tree blob at 43000000 Booting using the fdt blob at 0x43000000 EHCI failed to shut down host controller. Loading Device Tree to 49ff5000, end 49fffb78 ... OK Starting kernel ...


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3